<template>
  <div>
    <el-dialog title="撤回上报文件" :visible.sync="isShow" center :before-close="close">
      <el-form :model="form" :rules="rules" ref="ruleForm" label-position="right" label-width="120px">
        <el-form-item label="撤回原因" prop="reason">
          <el-input v-model="form.reason" type="textarea" :rows="5"></el-input>
        </el-form-item>
        <!-- <el-form-item label="扣款原因" prop="name">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="扣款金额" prop="deduction_price">
          <el-input v-model="form.deduction_price"></el-input>
        </el-form-item> -->
      </el-form>
      <div slot="footer" >
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="submint" :loading="btnLoading">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data () {
    // var validateMoney = (rule, value, callback) => {
    //   if (value === '') {
    //     callback()
    //   } else {
    //     if (!Number(value)) {
    //       callback(new Error('请输入正确的金额'));
    //     } else if (value <= 0) {
    //       callback(new Error('扣款金额必须大于0'));
    //     } else {
    //       callback()
    //     }
    //   }
    // }
    return {
      form: {
        reason: '',
        // name: '',
        // deduction_price: '',
      },
      isShow: false,
      rules: {
        reason: [
          { required: true, message: '请输入撤回原因', trigger: 'change' }
        ],
        // name: [
        //   { message: '请输入扣款原因', trigger: 'change' }
        // ],
        // deduction_price: [
        //   { validator: validateMoney, trigger: 'change' }
        // ],
      },
      id: '',
      btnLoading: false
    }
  },
  methods: {
    show (data) {
      this.id = data.id
      this.isShow = true
    },
    submint() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          this.submintPost()
        } else {
          return false;
        }
      })
    },
    submintPost() {
      let params = {
        finals: this.id,
        reason: this.form.reason,
      }
      // if(this.form.name != '' || this.form.deduction_price != '') {
      //   if (this.form.name == '' || this.form.deduction_price == '') {
      //     this.$message.error('扣款信息不能为空')
      //     return
      //   }
      // }
      // if (this.form.name != '') {
      //   params.name = this.form.name
      // }
      // if (this.form.deduction_price != '') {
      //   params.deduction_price = this.form.deduction_price
      // }
      this.btnLoading = true
      this.$axios.post(`api/order/${this.id}/agent_end_finish_file`, params).then((res) => {
        if (res.data.code == 200) {
          this.$message({
            type: 'success',
            message: '撤回上报文件成功！'
          })
          this.$emit('refresh')
          this.close()
          this.btnLoading = false
        } else {
          this.$message.error(res.data.message)
          this.close()
          this.btnLoading = false
        }
      })
    },
    close() {
      this.$refs['ruleForm'].resetFields()
      this.isShow = false
    }
  }
}
</script>

<style lang='less' type='text/css'>

</style>
